using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Backend.JYD.Model.Auth;

namespace Backend.JYD.EFDAL.Mapping
{
    public class MenuAuthInfoMap : EntityTypeConfiguration<MenuAuthInfo>
    {
        public MenuAuthInfoMap()
        {
            // Primary Key
            this.HasKey(t => new { t.MenuId, t.AuthId });

            // Properties
            this.Property(t => t.MenuId)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.AuthId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("MenuAuthInfo");
            this.Property(t => t.MenuId).HasColumnName("MenuId");
            this.Property(t => t.AuthId).HasColumnName("AuthId");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.Type).HasColumnName("Type");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");
            this.Property(t => t.UpdateTime).HasColumnName("UpdateTime");
            this.Property(t => t.OpId).HasColumnName("OpId");

            // Relationships
            this.HasRequired(t => t.AuthorityInfo)
                .WithMany(t => t.MenuAuthInfoes)
                .HasForeignKey(d => d.AuthId);
            this.HasRequired(t => t.MenuInfo)
                .WithMany(t => t.MenuAuthInfoes)
                .HasForeignKey(d => d.MenuId);

        }
    }
}
